package com.ld.wms.business.log.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ld.wms.business.log.mapper.InventoryOperateLogMapper;
import com.ld.wms.business.log.model.InventoryOperateLogModel;
import com.ld.wms.business.log.service.InventoryOperateLogService;
import com.ld.wms.business.log.vo.resp.InventoryOperateLogRespVo;
import com.ld.wms.business.user.model.UserAccountModel;
import com.ld.wms.business.user.service.UserAccountService;
import com.ld.wms.common.vo.GeneratePageListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 库存操作日志 服务实现类
 * </p>
 *
 * @author wangfeng
 * @since 2025-04-27
 */
@Service
public class InventoryOperateLogServiceImpl extends ServiceImpl<InventoryOperateLogMapper, InventoryOperateLogModel> implements InventoryOperateLogService {

    @Autowired
    private InventoryOperateLogMapper inventoryOperateLogMapper;

    @Autowired
    private UserAccountService userAccountService;

    @Override
    public GeneratePageListVo<InventoryOperateLogRespVo> getPageList(Integer type, Integer current, Integer size) {
        IPage<InventoryOperateLogRespVo> iPage = new Page<>(current, size);
        IPage<InventoryOperateLogRespVo> iPage1 = inventoryOperateLogMapper.selectPageList(iPage, type);
        Map<Long, UserAccountModel> allUserMap = userAccountService.getAllUserMap();
        for (InventoryOperateLogRespVo respVo : iPage1.getRecords()) {
            UserAccountModel userAccountModel = allUserMap.get(respVo.getCreateBy());
            respVo.setCreateName(userAccountModel.getAccountName());
        }
        return new GeneratePageListVo<>(iPage1);
    }
}
